Python/Python Mcq Set 5 Sample Test,Sample questions

Question:
 If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.

1. obj.__str__()

2.str(obj)

3.print obj

4. all of the mentioned

Posted Date:-2021-12-30 14:42:38


Question:
 Suppose s is “		World
”, what is s.strip()?

1. World

2. World

3. WORLD

4.World

Posted Date:-2021-12-30 14:36:48


Question:
 To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?

1. s[]

2.s.getitem(3)

3.s.__getitem__(3)

4.s.getItem(3)

Posted Date:-2021-12-30 14:41:31


Question:
 What will be the output of the following Python code?

>>>print("D", end = ' ')
>>>print("C", end = ' ')
>>>print("B", end = ' ')
>>>print("A", end = ' ')

1.DCBA

2. A, B, C, D

3. D C B A

4.D, C, B, A will be displayed on four lines

Posted Date:-2021-12-30 14:39:10


Question:
 What will be the output of the following Python code?

print("abc DEF".capitalize())

1.abc def

2.ABC DEF

3.Abc def

4. Abc Def

Posted Date:-2021-12-30 14:47:44


Question:
 What will be the output of the following Python code?

print(0xA + 0xB + 0xC)

1. 0xA0xB0xC

2.Error

3.0x22

4.33

Posted Date:-2021-12-30 14:30:03


Question:
 What will be the output of the following Python code?

x = (i for i in range(3))
for i in x:
    print(i)

1. 0 1 2

2.error

3. 0 1 2 0 1 2

4.none of the mentioned

Posted Date:-2021-12-30 14:19:01


Question:
 What will be the output of the following Python statement?(python 3.xx)

>>>print(format("Welcome", "10s"), end = '#')
>>>print(format(111, "4d"), end = '#')
>>>print(format(924.656, "3.2f"))

1.Welcome# 111#924.66

2.Welcome#111#924.66

3.Welcome#111#.66

4.Welcome # 111#924.66

Posted Date:-2021-12-30 14:39:37


Question:
Given a string example=”hello” what is the output of example.count(‘l’)?

1.2

2. 1

3.None

4.0

Posted Date:-2021-12-30 14:32:29


Question:
Say s=”hello” what will be the return value of type(s)?

1.int

2.bool

3.str

4.String

Posted Date:-2021-12-30 14:40:29


Question:
Suppose i is 5 and j is 4, i + j is same as ________

1. i.__add(j)

2. i.__add__(j)

3. i.__Add(j)

4.i.__ADD(j)

Posted Date:-2021-12-30 14:43:33


Question:
Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).

1. __345.355

2.___345.355

3.___345.355

4._____345.354

Posted Date:-2021-12-30 14:44:48


Question:
The format function, when applied on a string returns ______

1. Error

2. int

3.bool

4.str

Posted Date:-2021-12-30 14:38:15


Question:
The output of executing string.ascii_letters can also be achieved by:

1.string.ascii_lowercase_string.digits

2.string.ascii_lowercase+string.ascii_uppercase

3.string.letters

4.string.lowercase_string.uppercase

Posted Date:-2021-12-30 14:25:09


Question:
To check whether string s1 contains another string s2, use ____

1.s1.__contains__(s2)

2.s2 in s1

3.s1.contains(s2)

4.si.in(s2)

Posted Date:-2021-12-30 14:43:01


Question:
To concatenate two strings to a third what statements are applicable?

1. s3 = s1 . s2

2.s3 = s1.add(s2)

3.s3 = s1.__add__(s2)

4. s3 = s1 * s2

Posted Date:-2021-12-30 14:34:09


Question:
To return the length of string s what command do we execute?

1.s.__len__()

2. len(s)

3. size(s)

4.s.size()

Posted Date:-2021-12-30 14:42:11


Question:
What arithmetic operators cannot be used with strings?

1. +

2.*

3.–

4.all of the mentioned

Posted Date:-2021-12-30 14:25:59


Question:
What function do you use to read a string?

1.input(“Enter a string”)

2.eval(input(“Enter a string”))

3.enter(“Enter a string”)

4.eval(enter(“Enter a string”))

Posted Date:-2021-12-30 14:44:01


Question:
What is “Hello”.replace(“l”, “e”)?

1.Heeeo

2.Heelo

3.Heleo

4. None

Posted Date:-2021-12-30 14:41:06


Question:
What will be displayed by print(ord(‘b’) – ord(‘a’))?

1.0

2. 1

3. -1

4. 2

Posted Date:-2021-12-30 14:40:02


Question:
What will be the output of the “hello” +1+2+3?

1. hello123

2. hello

3.Error

4. hello6

Posted Date:-2021-12-30 14:38:41


Question:
What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
for a[-1] in a:
    print(a[-1])

1.0 1 2 3

2.0 1 2 2

3. 3 3 3 3

4.error

Posted Date:-2021-12-30 14:20:55


Question:
What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
for a[0] in a:
    print(a[0])

1.0 1 2 3

2.0 1 2 2

3. 3 3 3 3

4.error

Posted Date:-2021-12-30 14:21:20


Question:
What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
i = -2
for i not in a:
    print(i)
    i += 1

1. -2 -1

2.0

3. error

4.none of the mentioned

Posted Date:-2021-12-30 14:21:47


Question:
What will be the output of the following Python code snippet?

string = "my name is x"
for i in ' '.join(string.split()):
    print (i, end=", ")

1.m, y, , n, a, m, e, , i, s, , x,

2.m, y, , n, a, m, e, , i, s, , x

3.my, name, is, x,

4.error

Posted Date:-2021-12-30 14:22:13


Question:
What will be the output of the following Python code?

>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]

1.olleh

2.hello

3.h

4.o

Posted Date:-2021-12-30 14:25:34


Question:
What will be the output of the following Python code?

>>>example = "helle"
>>>example.find("e")

1.Error

2. -1

3.1

4.0

Posted Date:-2021-12-30 14:32:53


Question:
What will be the output of the following Python code?

>>>example = "helle"
>>>example.rfind("e")

1.-1

2.4

3. 3

4.1

Posted Date:-2021-12-30 14:33:19


Question:
What will be the output of the following Python code?

>>>example = "snow world"
>>>example[3] = 's'
>>>print example

1. snow

2.snow world

3. Error

4.snos world

Posted Date:-2021-12-30 14:31:39


Question:
What will be the output of the following Python code?

>>>example = "snow world"
>>>print("%s" % example[4:7])

1.wo

2.world

3.sn

4.rl

Posted Date:-2021-12-30 14:30:49


Question:
What will be the output of the following Python code?

>>>example="helloworld"
>>>example[::-1].startswith("d")

1.dlrowolleh

2. True

3.-1

4.None

Posted Date:-2021-12-30 14:33:45


Question:
What will be the output of the following Python code?

>>>max("what are you")

1.error

2.u

3. t

4. Y

Posted Date:-2021-12-30 14:32:06


Question:
What will be the output of the following Python code?

>>>print (r"
hello")

1. a new line and hello

2. hello

3.the letter r and then hello

4.error

Posted Date:-2021-12-30 14:26:34


Question:
What will be the output of the following Python code?

>>>str1="helloworld"
>>>str1[::-1]

1. dlrowolleh

2.hello

3.world

4.helloworld

Posted Date:-2021-12-30 14:29:35


Question:
What will be the output of the following Python code?

for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

1.0 1 2 3 4 Here

2.0 1 2 3 4 5 Here

3.0 1 2 3 4

4.1 2 3 4 5

Posted Date:-2021-12-30 14:22:47


Question:
What will be the output of the following Python code?

print('*', "abcdef".center(7), '*')

1. * abcdef *

2.* abcdef *

3. *abcdef *

4. * abcdef*

Posted Date:-2021-12-30 14:49:48


Question:
What will be the output of the following Python code?

print('*', "abcdef".center(7), '*', sep='')

1.* abcdef *

2.* abcdef *

3. *abcdef *

4.* abcdef*

Posted Date:-2021-12-30 14:50:13


Question:
What will be the output of the following Python code?

print("abc. DEF".capitalize())

1.abc. def

2.ABC. DEF

3. Abc. def

4.Abc. Def

Posted Date:-2021-12-30 14:48:09


Question:
What will be the output of the following Python code?

print("abcdef".center())

1.cd

2.abcdef

3. error

4.none of the mentioned

Posted Date:-2021-12-30 14:48:40


Question:
What will be the output of the following Python code?

print("abcdef".center(0))

1. cd

2. abcdef

3. error

4.none of the mentioned

Posted Date:-2021-12-30 14:49:24


Question:
What will be the output of the following Python code?

string = "my name is x"
for i in string.split():
    print (i, end=", ")

1.m, y, , n, a, m, e, , i, s, , x

2. m, y, , n, a, m, e, , i, s, , x

3.my, name, is, x,

4.error

Posted Date:-2021-12-30 14:20:24


Question:
What will be the output of the following Python code?

string = "my name is x"
for i in string:
    print (i, end=", ")

1.m, y, , n, a, m, e, , i, s, , x,

2.m, y, , n, a, m, e, , i, s, , x

3.my, name, is, x,

4. error

Posted Date:-2021-12-30 14:20:01


Question:
What will be the output of the following Python code?

x = (i for i in range(3))
for i in x:
    print(i)
for i in x:
    print(i)

1. 0 1 2

2.error

3.0 1 2 0 1 2

4.none of the mentioned

Posted Date:-2021-12-30 14:19:31


Question:
What will be the output of the following Python statement?

>>>"a"+"bc"

1.a

2.bc

3.bca

4.abc

Posted Date:-2021-12-30 14:24:16


Question:
What will be the output of the following Python statement?

>>>"abcd"[2:]

1. a

2.ab

3.cd

4.dc

Posted Date:-2021-12-30 14:24:46


Question:
What will be the output of the following Python statement?

>>>chr(ord('A'))

1.A

2. B

3. a

4. error

Posted Date:-2021-12-30 14:35:10


Question:
What will be the output of the following Python statement?

>>>print('new' 'line')

1. Error

2.Output equivalent to print ‘new line’

3.newline

4.new line

Posted Date:-2021-12-30 14:26:56


Question:
What will be the output of the following Python statement?

>>>print(chr(ord('b')+1))

1.a

2.b

3. c

4. A

Posted Date:-2021-12-30 14:35:55


Question:
Which of the following statement prints helloexample	est.txt?

1.print(“helloexample est.txt”)

2.print(“hello\example\test.txt”)

3.print(“hello”example”test.txt”)

4.print(“hello”example” est.txt”)

Posted Date:-2021-12-30 14:36:21


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!